/*
    This file is part of ciberRatoToolsSrc.

    Copyright (C) 2001-2006 Universidade de Aveiro

    ciberRatoToolsSrc is free software; you can redistribute it and/or modify
    it under the terms of the GNU General Public License as published by
    the Free Software Foundation; either version 2 of the License, or
    (at your option) any later version.

    ciberRatoToolsSrc is distributed in the hope that it will be useful,
    but WITHOUT ANY WARRANTY; without even the implied warranty of
    MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
    GNU General Public License for more details.

    You should have received a copy of the GNU General Public License
    along with Foobar; if not, write to the Free Software
    Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA  02110-1301  USA
*/
/*
 * cbParameters.cpp
 */

#include "cbparameters.h"
#include "cbsensor.h"

#include <stdio.h>

cbParameters::cbParameters()
{
	simTime = 2000;
	cycleTime = 75;
	runningTimeout = 1500;
	GPSOn = false;
	scoreSensorOn = false;
	showActions = false;

	//Noise
	motorsNoise = compassNoise = beaconNoise = obstacleNoise = 0.0;
	//Requests
	nReqPerCycle=2;
	obstacleRequestable   = cbIRSensor::sensorRequestable; 
	beaconRequestable     = cbBeaconSensor::sensorRequestable; 
	compassRequestable    = cbCompassSensor::sensorRequestable; 
	groundRequestable     = cbGroundSensor::sensorRequestable;
	collisionRequestable  = cbCollisionSensor::sensorRequestable;
	//Latencies
	obstacleLatency    = cbIRSensor::sensorLatency; 
	beaconLatency      = cbBeaconSensor::sensorLatency; 
	compassLatency     = cbCompassSensor::sensorLatency; 
	groundLatency      = cbGroundSensor::sensorLatency;
	collisionLatency   = cbCollisionSensor::sensorLatency;

	beaconAperture = cbBeaconSensor::sensorAperture;
}

cbParameters::~cbParameters()
{
}

int cbParameters::toXml(char *buff, int len)
{
	int cnt = sprintf(buff, "<Parameters SimTime=\"%u\" CycleTime=\"%u\"\n"
			"\t\tCompassNoise=\"%g\" BeaconNoise=\"%g\" ObstacleNoise=\"%g\"\n"
			"\t\tMotorsNoise=\"%g\" RunningTimeout=\"%u\"\n"
			"\t\tGPS=\"%s\" ScoreSensor=\"%s\" ShowActions=\"%s\" NBeacons=\"%d\" \n",
			simTime, cycleTime, 
			compassNoise, beaconNoise, obstacleNoise, motorsNoise,
			runningTimeout, (GPSOn?"On":"Off"), (scoreSensorOn?"On":"Off"),(showActions?"True":"False"),
			nBeacons);

	cnt = cnt + sprintf(buff+cnt, 
			"\t\tRequestsPerCycle=\"%d\" \n"
			"\t\tObstacleRequestable=\"%s\" BeaconRequestable=\"%s\" \n"
			"\t\tGroundRequestable=\"%s\" CompassRequestable=\"%s\"\n"
			"\t\tCollisionRequestable=\"%s\"\n",
			nReqPerCycle,
			(obstacleRequestable?"On":"Off"), (beaconRequestable?"On":"Off"),
			(groundRequestable?"On":"Off"), (compassRequestable?"On":"Off"),
			(collisionRequestable?"On":"Off"));

	cnt = cnt + sprintf(buff+cnt, 
			"\t\tObstacleLatency=\"%d\" BeaconLatency=\"%d\" \n"
			"\t\tGroundLatency=\"%d\" CompassLatency=\"%d\"\n"
			"\t\tCollisionLatency=\"%d\"\n",
			obstacleLatency, beaconLatency,
			groundLatency, compassLatency, collisionLatency);

	cnt = cnt + sprintf(buff+cnt, 
			"\t\tBeaconAperture=\"%f\"\n",
			beaconAperture);


	if(!labFilename.isNull())
	    cnt = cnt + sprintf(buff + cnt, "\t\tLab=\"%s\"\n", labFilename.latin1());;
	if(!gridFilename.isNull())
	    cnt = cnt + sprintf(buff + cnt, "\t\tGrid=\"%s\"\n", gridFilename.latin1());;

	cnt = cnt + sprintf(buff + cnt, "/>\n"); 
	return cnt;
}
